#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using ll = long long;

const ll max_n = 2e5+5;
const ll MOD = 10007;
ll n, w[max_n];

std::vector<ll> next[max_n];
ll brothers_from_father[max_n];

ll ans_max,ans_sum;

#ifdef ONLINE_JUDGE
    #define DEBUG(code)
#else
    #define DEBUG(code)code
#endif

DEBUG(
    template<class ...Args>
    void debug(Args&&...args){
        std::cout<<"[DEBUG]: ";
        (std::cout<<...<<std::forward<Args>(args));
        std::cout<<'\n';
    }
)

void dfs(const ll now, const ll father,const ll grand_father){
    if(father == -1){
        for(const auto i:next[now]){
            if(i==father)continue;
            dfs(i, now,-1);
        }
        return;
    }else if(grand_father == -1){
        for(const auto i:next[now]){
            if(i==father)continue;
            dfs(i,now,father);
        }
        return;
    }

    DEBUG(
        debug("args: ",now," ",father," ",grand_father);
    )
    if(!next[now].empty()){
        for (const auto i: next[now]) {
            if(i==father)continue;
            dfs(i,now,father);
        }
    }
    for(const auto i : next[father]){
        if(i != now){
            ans_max = std::max(ans_max, w[i]*w[now]);
            DEBUG(
                debug("update max ",ans_max);
            )
            DEBUG(
                debug("brother: ",w[i],' ',w[now]);
            )
            brothers_from_father[father] = ((w[i]*w[now]) % MOD + brothers_from_father[father]) % MOD;
        }
    }
    DEBUG(
        debug(w[now],' ',w[grand_father]);
    )
    ans_max = std::max(ans_max, w[now] * w[grand_father]);
    DEBUG(
        debug("update max ",ans_max);
    )
    ans_sum  = (ans_sum + (w[now]*w[grand_father]) % MOD) % MOD;
}

int main(){
    std::cin>>n;
    for(ll i{1};i<n;i++){
        ll a,b;
        std::cin>>a>>b;
        next[a].push_back(b);
        next[b].push_back(a);
    }
    for(ll i{1};i<=n;i++){
        std::cin>>w[i];
    }
    dfs(1, -1, -1);

    for(ll i{1};i<=n;i++){
        DEBUG(
            debug("from brother ",i," add :",brothers_from_father[i]);
        )
        ans_sum  = (ans_sum + brothers_from_father[i]) % MOD;
    }

    std::cout<<ans_max<<' '<<(ans_sum) % MOD<<'\n';
}

/*

4
1 2
2 3
2 4
1 2 3 4
(3,4),(4,3),(1,3),(3,1),(1,4),(4,1)
max = 12
sum = 12+12+3+3+4+4 = 38

*/